package com.bodu.depress.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.global.annon.TraceLog;
import com.bodu.depress.entity.vo.DepressSolutionVo;
import com.bodu.depress.entity.request.DepressSolutionRequest;
import com.bodu.depress.service.DepressSolutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题目答案 API
 *
 * @author Administrator
 */
@Api(tags = "题目答案 API")
@RestController
@RequestMapping("/depressSolution")
public class DepressSolutionController
        extends AbstractCommonController<DepressSolutionService, DepressSolutionRequest, DepressSolutionVo> {

    private final DepressSolutionService depressSolutionService;

    public DepressSolutionController(DepressSolutionService depressSolutionService) {
        this.depressSolutionService = depressSolutionService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(depressSolutionService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存题目答案")
    public Result<Integer> save(@RequestBody DepressSolutionRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(depressSolutionService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新题目答案")
    public Result<Integer> update(@RequestBody DepressSolutionRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(depressSolutionService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("题目答案-查询")
    public Result<List<DepressSolutionVo>> listPage(@RequestBody ParamReq req) {
        return super.listPage(depressSolutionService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("题目答案-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(depressSolutionService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("题目答案-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<DepressSolutionRequest> req) {
        return super.page(depressSolutionService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除题目答案")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(depressSolutionService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除题目答案")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(depressSolutionService, ids);
    }

    @GetMapping("/getSolutionModelByQuestionId/{questionId}")
    public Result<DepressSolutionVo> getSolutionModelByQuestionId(@PathVariable("questionId") Long questionId) {
        DepressSolutionVo depressSolutionVo = depressSolutionService.getSolutionModelByQuestionId(questionId);
        return Result.success(depressSolutionVo);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
